package com.fr.test;

import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;

public class test {

    public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
            SecurityException {
        // List<String> words = Arrays.asList("aaa", "aaa");
        // System.out.println(list2String(words));
        // Boolean aa = null;
        // if (aa != null && aa) {
        //
        // }
        // Map<Long, Long> map = new HashMap<>();
        // map.put(1L, 3L);
        // Long l = 1L;
        // System.out.println(map.get(l));
        // int[] arr = new int[4];
        // arr[0] = 1;
        // int p = arr[0] * 3 + arr[1] * 2 + arr[3];
        // System.out.println(p);
        // Integer a = null;
        // System.out.println(2 == a);
        // A a = new A(1);
        // changeA(a);
        // System.out.println(a.a);
        // Integer a = 127;
        // Integer b = 127;
        // System.out.println(null == B.a.getValue());
        // Date d = new Date(1479916800000L);
        // System.out.println(getDay(d, new Date()));
        // List<s> list = new ArrayList<>();
        // list.add(new s());
        // list.add(new s());
        // list.add(new s());
        // list.add(new s());
        // list.add(new s());
        // List<s> sub = list.subList(1, 2);
        // System.out.println(JSON.toJSONString(sub));
//        String[] s = "11|2".split("[|]");
//        for (String ss : s)
//            System.out.println(ss);
        // bb b = null;
        // switch (b) {
        // case a:
        //
        // break;
        //
        // default:
        // break;
        // }
        // List<Integer> list = new ArrayList<>();
        // list.add(1);
        // list.add(2);
        // list.getClass().getMethod("add", Object.class).invoke(list, "abc");
        // for (int i = 0; i < list.size(); i++) {
        // System.out.println(list.get(i));
        // }
        // Long l1 = null;
        // Long l2 = 2L;
        // System.out.println(l2.equals(l1));
        // String a = "1,2,3,4";
        // System.out.println(a.replace(",", "|"));
//        Calendar c = Calendar.getInstance();
//        c.add(Calendar.DAY_OF_YEAR, -365);
//        System.out.println(c.getTimeInMillis());]
//    	String a = null;
//    	System.out.println("".equals(a));
//    	Integer.valueOf("null");
//    	System.out.println(isAfterSaturdayNoon());
//    	Double a = null;
//    	change(a);
//    	System.out.println(a);
//    	String s = "入台证";
//    	String [] ss = s.split("");
//    	for(String sss :ss){
//    		System.out.println(sss);
//    	}
    	Set<String> set =  new HashSet<String>();
    	Boolean a = null;
    	System.out.println(String.valueOf(a));
    	
    }
    public static void change(Double a){
    	 a = 123D;
    }
    public static boolean isAfterSaturdayNoon()
    {
      Calendar c = Calendar.getInstance();
      Calendar c2 = Calendar.getInstance();
      c2.set(11, 12);
      c2.set(7, 6);
      c2.set(12, 0);
      c2.set(14, 0);
      System.out.println(new SimpleDateFormat("yyyyMMdd HHmmss SSS").format(c2.getTime()));
      return c.after(c2);
    }
    static class s {

    }

    private static void changeA(A a) {
        A b = new A(2);
        a = b;
        System.out.println(a.a);
    }

    public static String list2String(List<String> words) {
        if (CollectionUtils.isEmpty(words)) {
            return "";
        }
        long total = words.size();
        Map<String, Integer> map = new HashMap<String, Integer>();
        for (String word : words) {
            Integer i = map.get(word);
            if (i == null) {
                map.put(word, 1);
            } else {
                map.put(word, ++i);
            }
        }
        return sortMap(map, total);
    }

    protected static String sortMap(Map<String, Integer> oldMap, long total) {
        ArrayList<Map.Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(oldMap.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {

            @Override
            public int compare(Entry<String, Integer> arg0, Entry<java.lang.String, Integer> arg1) {
                return arg1.getValue() - arg0.getValue();
            }
        });
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (int i = 0; i < list.size() && i < 10; i++) {
            int value = list.get(i).getValue();
            if (isFirst) {
                sb.append(list.get(i).getKey()).append(":").append(value).append(":").append(getDouble2(value, total));
                isFirst = false;
            } else {
                sb.append(",").append(list.get(i).getKey()).append(":").append(value).append(":").append(getDouble2(value, total));
            }
        }
        int count = 0;
        for (int i = 10; i < list.size(); i++) {
            count += list.get(i).getValue();
        }
        if (count > 0) {
            sb.append(",").append("其他").append(":").append(count).append(":").append(getDouble2(count, total));
        }
        return sb.toString();
    }

    private static String getDouble2(int n, long total) {
        DecimalFormat df = new DecimalFormat("0.00");
        return df.format(1.0D * n / total);
    }

    static class A {
        int a;

        public A(int a) {
            this.a = a;
        }
    }

    private static long getDay(Date d1, Date d2) {
        if (d1 == null || d2 == null) {
            return -1000001L;
        }
        return (d1.getTime() - d2.getTime()) / 86400000L;
    }

    enum bb {
        a, b, c;
    }
}
